/***
 * jyh
 * 全局的js事件发布和订阅
 */
	GlobalEvent	= {
		event:{},
		/***
		 * 添加监听事件
		 * @param eventName 事件名称
		 * @param eventHandler 事件handler对象
		 */
		addListener:function(eventName,eventHandler,handlerScope){
			var events = this.event[eventName];
			if( events ){
				this.event[eventName].push({handler:eventHandler,scope:handlerScope});
			}else{
				this.event[eventName] = [{handler:eventHandler,scope:handlerScope}] ;
			}
		},
		/***
		 * 移除一个事件
		 * @param eventName
		 */
		removeListener:function(eventName){
			var events = this.event[eventName];
			if( events ){
				delete this.event[eventName] ;
			}
		},
		/***
		 * 触发事件
		 * @param eventName 事件名
		 * @param eventParams 事件handler的参数
		 */
		fireEvent:function(eventName,eventParams){
			top.GlobalEvent._fireEvent(eventName,eventParams);
		},
		_fireEvent:function(eventName,eventParams){
			 //执行当前iframe中的事件
			var events = this.event[eventName];
			if( events ){
				var len = events.length;
				for( var i=0 ; i<len ;i++){
					var eventObj = events[i];
					var handler = eventObj.handler;
					var scope = eventObj.scope;
					if( scope ){
						handler.call(scope,eventParams);
					}else{
						handler(eventParams);
					}
				}
			}
			//执行当前frame中所有子frame中的事件
			var frames =document.getElementsByTagName("IFRAME");
			var len = frames.length;
			for (var i = 0; i < len; i++) {
				if (frames[i].contentWindow.GlobalEvent){
					frames[i].contentWindow.GlobalEvent._fireEvent(eventName, eventParams);
				}
			}
//			var frames = window.frames;			
//			var len = frames.length;
//			for (var i = 0; i < len; i++) {
//				if (frames[i] && frames[i].GlobalEvent)
//					frames[i].GlobalEvent._fireEvent(eventName, eventParams);
//			}
			
		}
	};

